package com.hejjon.controller;

import com.hejjon.core.bean.ResponseResult;
import com.hejjon.core.controller.BaseController;
import com.hejjon.domain.request.BusinessFeatureCreateRequest;
import com.hejjon.domain.request.BusinessFeatureQueryRequest;
import com.hejjon.domain.request.BusinessFeatureUpdateRequest;
import com.hejjon.domain.response.BusinessFeatureCreateResponse;
import com.hejjon.domain.response.BusinessFeatureQueryResponse;
import com.hejjon.domain.response.BusinessFeatureRemoveResponse;
import com.hejjon.domain.response.BusinessFeatureUpdateResponse;
import com.hejjon.domain.vo.BusinessFeatureVO;
import com.hejjon.service.IBusinessFeatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 666
 * 业务特征 Controller
 * @author: cs
 * @date: 2025-02-26 14:20:09
 * @since: 1.0
 */
@RestController
@RequestMapping("/feature/busiFeature")
public class BusinessFeatureController extends BaseController {


    @Autowired
    private IBusinessFeatureService businessFeatureService;

    @PostMapping("/create")
    public ResponseResult create(@Valid @RequestBody BusinessFeatureCreateRequest request) {
        BusinessFeatureCreateResponse response = businessFeatureService.create(request);
        return toResult(response);
    }

    @PostMapping("/update")
    public ResponseResult update(@Valid @RequestBody BusinessFeatureUpdateRequest request) {
        BusinessFeatureUpdateResponse response = businessFeatureService.update(request);
        return toResult(response);
    }

    /**
     * 查询特征 树结构
     */
    @PostMapping("/queryTreeList")
    public ResponseResult queryTreeList(@RequestBody BusinessFeatureQueryRequest request) {
        BusinessFeatureQueryResponse response = businessFeatureService.queryTreeData(request);
        return success(response);
    }

    /**
     * 查询扁特征数据列表
     */
    @PostMapping("/queryFeatureList")
    public ResponseResult queryFeatureList(@Valid @RequestBody BusinessFeatureQueryRequest request) {
        List<BusinessFeatureVO> businessFeatureVOS = businessFeatureService.queryList(request);
        return success(businessFeatureVOS);
    }


    @GetMapping("/removeById")
    public ResponseResult removeById(@RequestParam("id") String id) {
        BusinessFeatureRemoveResponse response = businessFeatureService.removeById(id);
        return toResult(response.isStatus(), "业务特征删除成功！");
    }


    @GetMapping("/getCreateTableSql")
    public ResponseResult getCreateTableSql(@RequestParam String featureId) {
        String tableSql = businessFeatureService.getCreateTableSql(featureId);
        return success("", tableSql);
    }





}
